// import{LOGIN_TYPE,LOGOUT_TYPE} from '../actions/user'
let userinfo = localStorage.getItem("userinfo");
try {
  userinfo = JSON.parse(userinfo) || {};
} catch (err) {
  userinfo = {};
}
const initState = {
  userinfo,
};
const reducer = function (state = initState, action) {
  let newState = state;
  switch (action.type) {
    case "login":
      newState = {
        userinfo: action.payload,
      };
      localStorage.setItem("userinfo", JSON.stringify(action.payload));
      return newState;
    case "logout":
      newState = {
        userinfo: {},
      };
      localStorage.removeItem("userinfo");
      return newState;
    default:
      return newState;
  }
};

export default reducer;
